import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

class Student {
	public Student(String id, int age, String firstName, String lastName) {
		this.id = id;
		this.age = age;
		this.firstName = firstName;
		this.lastName = lastName;
	}

	// an id, alpha-numeric
	// age, number
	// first name
	// last name
	String id;
	int age;
	String firstName;
	String lastName;
	/* methods */
	// provide getters and setters
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	// override toString
	public String toString(){
		return " FirstName : "+firstName +" LastName : "+ lastName +" ID : "+ id + " Age : "+age;

	}
}
public class StudentListUtils {
	void printStudentsSortedById(List<Student> students) {
		IdComparotor idcomp = new IdComparotor();
		Collections.sort(students, idcomp);
		Iterator<Student> itr = students.iterator();
		while (itr.hasNext()) {
			//Student type = (Student) itr.nextElement();
			System.out.println((itr.next()).getId());

		}
	}

	void printStudentsSortedByFirstName(List<Student> students) {
		FirstNameComparotor nameComp = new FirstNameComparotor();
		Collections.sort(students , nameComp);
		Iterator<Student> itr = students.iterator();
		while (itr.hasNext()) {
			System.out.println((itr.next()).getFirstName());

		}
	}

	void printStudentsSortedByAge(List<Student> students) {
		AgeComparotor ageCom = new AgeComparotor();
		Collections.sort(students , ageCom);
		Iterator<Student> itr = students.iterator();
		while (itr.hasNext()) {
			System.out.println((itr.next()).getAge());

		}
	}

	public static void main(String args[]) {
		// create bunch of students with different names, ages, etc
		// print the students sorted by id, first name, age
		Student S1 = new Student("61a",13,"laxmi","bayyana" );
		Student S2 = new Student("62a",15,"rao","bayyana");
		Student S3 = new Student("63a",23,"sree","bayyana");
		Student S4 = new Student("64a",35,"durga","bayyana");
		Student S5 = new Student("65a",11,"babu","bayyana");
		Student S6 = new Student("66a",12,"sai","yarlagadda");
		Student S7 = new Student("67a",17,"gouri","gade");
		List<Student> stuList = new ArrayList<Student>();
		stuList.add(S1);
		stuList.add(S2);
		stuList.add(S3);
		stuList.add(S4);
		stuList.add(S5);
		stuList.add(S6);
		stuList.add(S7);
		StudentListUtils  stuSort = new StudentListUtils();
		System.out.println("List of Student age's in sorted order");
		stuSort.printStudentsSortedByAge(stuList);
		System.out.println("\n");
		System.out.println("List of Student Name's in sorted order");
		stuSort.printStudentsSortedByFirstName(stuList);
		System.out.println("\n");
		System.out.println("List of Student Id's in sorted order");
		stuSort.printStudentsSortedById(stuList);
		
		
	}


}

class IdComparotor implements Comparator<Student>{

	@Override
	public int compare(Student s1, Student s2) {
		// TODO Auto-generated method stub
		return s1.getId().compareTo(s2.getId());
	}

}
class FirstNameComparotor implements Comparator<Student>{

	@Override
	public int compare(Student s1, Student s2) {
		// TODO Auto-generated method stub
		return s1.getFirstName().compareTo(s2.getFirstName());
	}

}
class AgeComparotor implements Comparator<Student>{

	@Override
	public int compare(Student s1, Student s2) {
		// TODO Auto-generated method stub
		if( s1.getAge() == (s2.getAge())){
			return 0;
		}else {
			if(s1.getAge() < (s2.getAge())){
				return -1;
			}
		}
		return 1;
	}


	public int compareV2(Student s1, Student s2) {
		// TODO Auto-generated method stub
		if( s1.getAge() == s2.getAge()){
			return 0;
		} else if (s1.getAge() < s2.getAge()){
			return -1;
		} else {
			return 1;
		}
	}

	public int compareV3(Student s1, Student s2) {
		// TODO Auto-generated method stub
		return new Integer(s1.getAge()).compareTo(s2.getAge());
	}



}

